﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Windows;

namespace Exe1
{
    public struct itm 
    {
        public string title, authors, zhaiyao;
    }
    public partial class Form1 : Form
    {
        public MyContainer m_vPapars;
        
        public Form1()
        {
            InitializeComponent();

            // 初始化数据列
            DataGridViewTextBoxColumn colName = new DataGridViewTextBoxColumn();
            colName.HeaderText = "论文名";
            grdPapers.Columns.Add(colName);
            DataGridViewTextBoxColumn colKeys = new DataGridViewTextBoxColumn();
            colKeys.HeaderText = "作者";
            grdPapers.Columns.Add(colKeys);
            DataGridViewTextBoxColumn colAbstract = new DataGridViewTextBoxColumn();
            colAbstract.HeaderText = "摘要";
            grdPapers.Columns.Add(colAbstract);

            // 初始化变量
            m_vPapars = new MyDBContainer("E:\\程序\\辅修课程序\\lei\\papers.mdb");
            
        }
        public void reloadData()
        {
            grdPapers.Rows.Clear();

            int i = 0;
            for (i = 0; i < m_vPapars.getCount(); i++)
            {
                grdPapers.Rows.Add();
                DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                cell.Value = m_vPapars.get(i).title;
                grdPapers[0, i] = cell;

                DataGridViewTextBoxCell cell1 = new DataGridViewTextBoxCell();
                cell1.Value = m_vPapars.get(i).authors;
                grdPapers[1, i] = cell1;

                DataGridViewTextBoxCell cell2 = new DataGridViewTextBoxCell();
                cell2.Value = m_vPapars.get(i).zhaiyao;
                grdPapers[2, i] = cell2;
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmAdd frmAdd = new FrmAdd();
            frmAdd.frmPa = this;
            frmAdd.mode = 0;
            if (frmAdd.ShowDialog() == DialogResult.OK)
            {
                
            } 
            else
            {
               
            }
            

        }

        private void btnMod_Click(object sender, EventArgs e)
        {
            FrmAdd frmAdd = new FrmAdd();
            frmAdd.frmPa = this;
            frmAdd.mode = 1;
            int curR = grdPapers.CurrentRow.Index;
            //DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
            frmAdd.tbxTitle.Text = grdPapers[0, curR].Value.ToString();
            //DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
            frmAdd.tbxAuthor.Text = grdPapers[1, curR].Value.ToString();
            //DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
            frmAdd.tbxAbstract.Text = grdPapers[2, curR].Value.ToString();
            frmAdd.ShowDialog();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            FrmQuery frmQuery = new FrmQuery();
            frmQuery.frmPa = this;

            frmQuery.ShowDialog();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            reloadData();
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("是否删除？", "确认窗口", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {
                int curR = grdPapers.CurrentRow.Index;
                m_vPapars.remove(curR);

                reloadData();
            }            
            
        }
    }
}
